﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InstrumentCheck.Module;
using InstrumentCheck.BLL;

namespace InstrumentCheck.WebAppUI
{
    public partial class DraftBox : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                User userInfo = Session["UserInfo"] as User;
                List<ApplyForm> list = DraftBox_bll.GetDraftBox(userInfo.EmpNO);
                BindGridView(list);
            }
        }

        private void BindGridView(List<ApplyForm> list)
        {
            gvDraft.DataSource = list;
            gvDraft.DataBind();
            if (list.Count > 0)
                gvDraft.Visible = true;
            else
                gvDraft.Visible = false;
        }

        protected void gvDraft_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[0].Visible = false;
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ApplyForm form = e.Row.DataItem as ApplyForm;
                e.Row.Cells[3].Text = form.Applicant.EmpChineseName;
                e.Row.Cells[4].Text = form.Item.AssetNO;
                e.Row.Cells[5].Text = form.Item.ChiName;
                e.Row.Cells[6].Text = form.Item.Spec;
                e.Row.Cells[7].Text = form.Item.ModelNO;
                e.Row.Cells[8].Text = "草稿，未送出";
                e.Row.Cells[2].Text = "<a href='" + this.PageURL() + "/CorrectItem.aspx?ID=" + form.FormID + "'>" + form.ApplyDate.ToString("yyyy/MM/dd") + "</a>";
            }
        }
    }
}
